/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package thread.demo.newpackage;

import java.io.*;
import java.util.*;

/**
 *
 * @author diemtrang
 */
public class CopyFile {

    public CopyFile() {
    }

    public static void main(String[] args) {
        List a = new ArrayList<>(1);
        LinkedList ll = new LinkedList();
        TreeMap tm = new TreeMap();
        tm.put(1, "abc");
        tm.put(2, 3);
        int[] aa = new int[10];

        for (Object i : tm.keySet()) {
            System.out.println(tm.get(i));
        }
        System.exit(1);


        // TODO code application logic here
        System.out.println("\t **** Welcome to the File Copier" + "Application ****");

        // Accept the location of the source file
        System.out.println("Enter the path of source file along" + "with the filename:");
        Scanner input = new Scanner(System.in);
        String path = input.next();

        // Create a File object
        File fileName = new File(path);
        String location = path.substring(0, path.indexOf(fileName.getName()));
        try {
            // Create an stream to read from the file
            FileInputStream fin = new FileInputStream(path);

            // Accept the location where the file is to be copied
            System.out.println("\n Enter the path where file is to be copied:");
            String copy = input.next();

            // Check if the location of the files is the same as the location
            // where the file is to be copied

            if (copy.equals(location)) {
                System.out.println("The source and the destination" + "path are the same");

                // Close all system resources
                fin.close();
                System.exit(0);
            } else {
                // Create a stream to write to the copy
                FileOutputStream fout = new FileOutputStream(copy + fileName.getName());
                FileWriter fw = new FileWriter("Account.txt");
                int data;
                while ((data = fin.read()) != -1) {
                    fout.write(data);
                }
                System.out.println("A copy of the file :" + fileName.getName()
                        + "has been successfully created at the location :"
                        + copy + fileName.getName() + "!");

                // Close all system resources
                fin.close();
                fout.close();
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();

        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
